package com.myday.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.myday.system.domain.MyTimer;
import com.myday.system.service.IMyTimerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 计时器Controller
 * 
 * @author xiaofengs
 * @date 2024-05-21
 */
@RestController
@RequestMapping("/system/timer")
public class MyTimerController extends BaseController
{
    @Autowired
    private IMyTimerService myTimerService;

    /**
     * 查询计时器列表
     */
    @PreAuthorize("@ss.hasPermi('system:timer:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyTimer myTimer)
    {
        startPage();
        List<MyTimer> list = myTimerService.selectMyTimerList(myTimer);
        return getDataTable(list);
    }

    /**
     * 导出计时器列表
     */
    @PreAuthorize("@ss.hasPermi('system:timer:export')")
    @Log(title = "计时器", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyTimer myTimer)
    {
        List<MyTimer> list = myTimerService.selectMyTimerList(myTimer);
        ExcelUtil<MyTimer> util = new ExcelUtil<MyTimer>(MyTimer.class);
        util.exportExcel(response, list, "计时器数据");
    }

    /**
     * 获取计时器详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:timer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(myTimerService.selectMyTimerById(id));
    }

    /**
     * 新增计时器
     */
    @PreAuthorize("@ss.hasPermi('system:timer:add')")
    @Log(title = "计时器", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyTimer myTimer)
    {
        return toAjax(myTimerService.insertMyTimer(myTimer));
    }

    /**
     * 修改计时器
     */
    @PreAuthorize("@ss.hasPermi('system:timer:edit')")
    @Log(title = "计时器", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyTimer myTimer)
    {
        return toAjax(myTimerService.updateMyTimer(myTimer));
    }

    /**
     * 删除计时器
     */
    @PreAuthorize("@ss.hasPermi('system:timer:remove')")
    @Log(title = "计时器", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(myTimerService.deleteMyTimerByIds(ids));
    }
}
